*Title: Delivering remote learning using a low-tech solution: Evidence from an RCT during school closures  
*Author: Liang Choon Wang, Michael Vlassopoulos, Asad Islam, Hashibul Hassan 

*These codes generate Tables B1-B12 of the Appendix

***************************************************************************************
*Stata preparation - Only run once 
***************************************************************************************
*ssc install omegacoef, replace

***************************************************************************************
*TABLE B1. Survey attrition rate 
***************************************************************************************
cd ..
pwd
use "Data\IVR_Data.dta", clear
cd "Output"

tab treatment_arms attrit, chi2 lrchi2 matcell(x)

putexcel set "Table B1.xlsx", replace 

putexcel A1 = "Particulars"		B1 = "(1) T1: Standard"	D1 = "(2) T2: Extended" F1 = "(3) C: Control" 	H1 = "(4) Total"
putexcel B2 = "N" C2 = "%" D2 = "N" E2 = "%" F2 = "N" G2 = "%"	H2 = "N" I2 = "%"
putexcel (B1:C1) (D1:E1) (F1:G1), merge hcenter vcenter

putexcel A4 = "Attrited"		B4 = (x[1,2]) 	C4 = (x[1,2]/(x[1,1]+x[1,2]))	D4 = (x[2,2])					E4 = (x[2,2]/(x[2,1]+x[2,2])) ///
								F4 = (x[3,2])	G4 = (x[3,2]/(x[3,1]+x[3,2])) 	H4 = (x[1,2]+x[2,2]+x[3,2]) 	I4 = ((x[1,2]+x[2,2]+x[3,2])/r(N))

putexcel A3 = "Not attrited"	B3 = (x[1,1])	C3 = (x[1,1]/(x[1,1]+x[1,2]))	D3 = (x[2,1])					E3 = (x[2,1]/(x[2,1]+x[2,2])) ///
								F3 = (x[3,1])	G3 = (x[3,1]/(x[3,1]+x[3,2])) 	H3 = (x[1,1]+x[2,1]+x[3,1])		I3 = ((x[1,1]+x[2,1]+x[3,1])/r(N))

putexcel 	A5 = "Total" B5 = formula(=SUM(B3:B4)) C5 = formula(=SUM(C3:C4))	D5 = formula(=SUM(D3:D4)) ///
			E5 = formula(=SUM(E3:E4)) F5 = formula(=SUM(F3:F4))	G5 = formula(=SUM(G3:G4)) H5 = formula(=SUM(H3:H4)) ///
			I5 = formula(=SUM(I3:I4))		
				
local chi2 			= string(`r(chi2)', "%9.4f")	
local chi2P			= string(`r(p)', "%9.2f")
putexcel A6 		= "Pearson’s Chi-squared test" 	B6 = "`chi2' (`chi2P')" 
putexcel (B6:I6), merge hcenter 
putexcel (B1:I6), hcenter

***************************************************************************************
*TABLE B2. Attrition, by treatment
***************************************************************************************
cd ..
pwd
use "Data\IVR_Data.dta", clear
cd "Output"

global control_list 		child_age child_gen baseline_literacy_score baseline_numeracy_score child_pvt_tuition father_edu_years mother_edu_years hh_mem family_income television smartphone hs_land reli_dummy

*Standard vs Control
foreach x in $control_list {
gen Int_std`x' = standard_treat*`x' 
}

putexcel set "Table B2.xlsx", replace 
putexcel A1 = "Variables"  B1 = "(1) T1 & C" C1 = "(2) T1 & C" D1 = "(3) T2 & C" E1 = "(4) T2 & C" F1 = "(5) T1, T2 & C" G1 = "(6) T1, T2 & C"

putexcel 	A2 = "T1: Standard treatment dummy" A3 = "T2: Extended treatment dummy" A4 = "Any treatment Dummy" ///
			A5 = "Constant" A6 = "Controls" A7 = "Interaction terms (treatment dummy × controls) " A8 = "Observations" ///
			A9 = "R-squared" A10 = "Joint F-test p-value on characteristics" A11 = "Joint F-test p-value on interactions"
				
reg attrit standard_treat if treatment_arms==1 | treatment_arms==3 , r cluster(VILLAGE_ID)
local mean 		= string(_b[standard_treat],"%9.2f")
local se 		= string(_se[standard_treat],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,1],"%9.4f")
local sig		= cond(`pval' < 0.005, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.0500, "*", "")))
putexcel B2 	= "`mean'`sig' (`se')"

local mean 		= string(_b[_cons],"%9.2f")
local se 		= string(_se[_cons],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,2],"%9.4f")
local sig		= cond(`pval' < 0.005, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.0500, "*", "")))
putexcel B5 	= "`mean'`sig' (`se')"  B6 = "No" B7 = "No" B8 = `e(N)' 
putexcel B9		= `e(r2)', nformat(number_d2)

reg attrit standard_treat $control_list Int_std* if treatment_arms==1 | treatment_arms==3, r cluster(VILLAGE_ID)
local mean 		= string(_b[standard_treat],"%9.2f")
local se 		= string(_se[standard_treat],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,1],"%9.4f")
local sig		= cond(`pval' < 0.005, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.0500, "*", "")))
putexcel C2 	= "`mean'`sig' (`se')"

local mean 		= string(_b[_cons],"%9.2f")
local se 		= string(_se[_cons],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,28],"%9.4f")
local sig		= cond(`pval' < 0.005, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.0500, "*", "")))
putexcel C5 	= "`mean'`sig' (`se')"  C6 = "Yes" C7 = "Yes" C8 = `e(N)'
putexcel C9		= `e(r2)', nformat(number_d2) 

test 	child_age child_gen  baseline_literacy_score  baseline_numeracy_score  child_pvt_tuition  father_edu_years  mother_edu_years  hh_mem  ///
		family_income  television  smartphone hs_land reli_dummy
putexcel C10 	= `r(p)', nformat(number_d2)

test 	 Int_stdchild_age Int_stdchild_gen Int_stdbaseline_literacy_score Int_stdbaseline_numeracy_score Int_stdchild_pvt_tuition Int_stdfather_edu_years Int_stdmother_edu_years Int_stdhh_mem Int_stdfamily_income Int_stdtelevision Int_stdsmartphone Int_stdhs_land Int_stdreli_dummy

putexcel C11 		= `r(p)', nformat(number_d2)

*Extended vs Control
foreach x in $control_list {
gen Int_lead`x' = extended_treat*`x' 
}

reg attrit extended_treat if treatment_arms==2 | treatment_arms==3, r cluster(VILLAGE_ID)
local mean 			= string(_b[extended_treat],"%9.2f")
local se 			= string(_se[extended_treat],"%9.2f")
matrix emat			= r(table)
local pval			= string(emat[4,1],"%9.4f")
local sig			= cond(`pval' < 0.005, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.0500, "*", "")))
putexcel D3 		= "`mean'`sig' (`se')"  

local mean 			= string(_b[_cons],"%9.2f")
local se 			= string(_se[_cons],"%9.2f")
matrix emat			= r(table)
local pval			= string(emat[4,2],"%9.4f")
local sig			= cond(`pval' < 0.005, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.0500, "*", "")))
putexcel D5 		= "`mean'`sig' (`se')"  D6 = "No" D7 = "No" D8 = `e(N)' 
putexcel D9			= `e(r2)', nformat(number_d2)

reg attrit extended_treat $control_list Int_lead* if treatment_arms==2 | treatment_arms==3, r cluster(VILLAGE_ID)
local mean 			= string(_b[extended_treat],"%9.2f")
local se 			= string(_se[extended_treat],"%9.2f")
matrix emat			= r(table)
local pval			= string(emat[4,1],"%9.4f")
local sig			= cond(`pval' < 0.005, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.0500, "*", "")))
putexcel E3 		= "`mean'`sig' (`se')"

local mean 			= string(_b[_cons],"%9.2f")
local se 			= string(_se[_cons],"%9.2f")
matrix emat			= r(table)
local pval			= string(emat[4,28],"%9.4f")
local sig			= cond(`pval' < 0.005, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.0500, "*", "")))
putexcel E5 		= "`mean'`sig' (`se')"  E6 = "Yes" E7 = "Yes" E8 = `e(N)'
putexcel E9			= `e(r2)', nformat(number_d2) 

test 	child_age child_gen baseline_literacy_score baseline_numeracy_score child_pvt_tuition father_edu_years mother_edu_years hh_mem family_income television smartphone hs_land reli_dummy
putexcel E10 		= `r(p)', nformat(number_d2)

test Int_leadchild_age Int_leadchild_gen Int_leadbaseline_literacy_score Int_leadbaseline_numeracy_score Int_leadchild_pvt_tuition Int_leadfather_edu_years Int_leadmother_edu_years Int_leadhh_mem Int_leadfamily_income Int_leadtelevision Int_leadsmartphone Int_leadhs_land Int_leadreli_dummy
putexcel E11 		= `r(p)', nformat(number_d2)

*Both treatment vs control 
foreach x in $control_list {
gen Int_treat`x' = any_treat*`x' 
}

reg attrit any_treat, r cluster(VILLAGE_ID)
local mean 			= string(_b[any_treat],"%9.2f")
local se 			= string(_se[any_treat],"%9.2f")
matrix emat			= r(table)
local pval			= string(emat[4,1],"%9.4f")
local sig			= cond(`pval' < 0.005, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.0500, "*", "")))
putexcel F4 		= "`mean'`sig' (`se')"  

local mean 			= string(_b[_cons],"%9.2f")
local se 			= string(_se[_cons],"%9.2f")
matrix emat			= r(table)
local pval			= string(emat[4,2],"%9.4f")
local sig			= cond(`pval' < 0.005, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.0500, "*", "")))
putexcel F5 		= "`mean'`sig' (`se')"  F6 = "No" F7 = "No" F8 = `e(N)' 
putexcel F9			= `e(r2)', nformat(number_d2)

reg attrit any_treat $control_list Int_treat*, r cluster(VILLAGE_ID)
local mean 			= string(_b[any_treat],"%9.2f")
local se 			= string(_se[any_treat],"%9.2f")
matrix emat			= r(table)
local pval			= string(emat[4,1],"%9.4f")
local sig			= cond(`pval' < 0.005, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.0500, "*", "")))
putexcel G4 		= "`mean'`sig' (`se')"

local mean 			= string(_b[_cons],"%9.2f")
local se 			= string(_se[_cons],"%9.2f")
matrix emat			= r(table)
local pval			= string(emat[4,28],"%9.4f")
local sig			= cond(`pval' < 0.005, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.0500, "*", "")))
putexcel G5 		= "`mean'`sig' (`se')"  G6 = "Yes" G7 = "Yes" G8 = `e(N)'
putexcel G9			= `e(r2)', nformat(number_d2) 

test 	child_age child_gen baseline_literacy_score baseline_numeracy_score child_pvt_tuition father_edu_years mother_edu_years hh_mem family_income television smartphone hs_land reli_dummy
putexcel G10 		= `r(p)', nformat(number_d2)

test 		Int_treatchild_age Int_treatchild_gen Int_treatbaseline_literacy_score Int_treatbaseline_numeracy_score Int_treatchild_pvt_tuition Int_treatfather_edu_years Int_treatmother_edu_years Int_treathh_mem Int_treatfamily_income Int_treattelevision Int_treatsmartphone Int_treaths_land Int_treatreli_dummy

putexcel G11 		= `r(p)', nformat(number_d2)

putexcel (B1:G11), hcenter vcenter

***************************************************************************************
*TABLE B3. Comparison between study sample and national sample survey
***************************************************************************************
*Module B2 from BIHS
cd ..
pwd
use "Data\BIHS 18-19\011_bihs_r3_male_mod_b2.dta", clear
keep if b2_10 <6 | b2_10 == 66 | b2_10 == 67
keep a01 mid_b2 b2_08a b2_08b b2_08c b2_08d b2_10 
rename mid_b2 mid
save "Data\BIHS 18-19\student_list.dta", replace 
cd "output"

*Module B1 from BIHS
cd ..
pwd
use "Data\BIHS 18-19\010_bihs_r3_male_mod_b1.dta", clear

*Households with son/Daughter of primary respondent studying in primary level
merge 1:1 a01 mid using "Data\BIHS 18-19\student_list.dta"
gen hh_primay_grade_mem = 1 if b1_03 == 3 & _merge == 3
replace hh_primay_grade_mem = 0 if hh_primay_grade_mem == .
bysort a01 : egen hh_primay_grade  = max(hh_primay_grade_mem) 
drop if hh_primay_grade == 0
save "Data\BIHS 18-19\HH_list.dta", replace

*Table 
cd "output"
putexcel set "Table B3.xlsx", replace 
putexcel 	A1 = "Variable"	B1 = "(1) BIHS Sample"	C1 = "(2) BIHS Observation" D1 = "(3) Study Sample" ///
			E1 = "(4) Observation"

putexcel 	A2 	= "Gender (1 if Boy)" A3 = "Access to private tuition (1 if Yes)" /// 
			A4 = "School Type (1 if Govt. School)" A5 = "Father's Age" /// 
			A6 = "Father's education (in years of schooling)" A7 = "Mother's Age"	///
			A8 = "Mother's education (in years of schooling)" /// 
			A9 = "No. of household member" A10 = "Family income (in BDT/ month)" ///
			A11 = "Access to TV (1 if yes)" A12	= "Access to phone (1 if yes)" ///
			A13	= "Homestead land (in decimal)" A14	= "Religion (1 if Islam)"  ///
			A15 = "HH head's occupation (% in Agriculture)"

*Children's gender - BIHS
putexcel set "Table B3.xlsx", modify 

replace b1_01 = 0 if b1_01 == 2
sum b1_01 if hh_primay_grade_mem == 1
local mean1 = string(r(mean),"%9.2f") 
local sd1 	=  string(r(sd),"%9.2f") 
putexcel B2 = "`mean1' (`sd1')"
putexcel C2 = `r(N)'

*Children's gender - Study sample
cd ..
pwd
use "Data\IVR_Data.dta", clear

cd "output"
putexcel set "Table B3", modify

sum child_gen
local mean2 = string(r(mean),"%9.2f") 
local sd2 =  string(r(sd),"%9.2f") 
putexcel D2 = "`mean2' (`sd2')"
putexcel E2 = `r(N)'

*access to private tuition - BIHS
cd ..
pwd
use "Data\BIHS 18-19\HH_list.dta", replace 

cd "output"
putexcel set "Table B3.xlsx", modify 

replace b2_08c = 0 if b2_08c == 2
sum b2_08c if hh_primay_grade_mem == 1
local mean1 = string(r(mean),"%9.2f") 
local sd1 =  string(r(sd),"%9.2f") 
putexcel B3 = "`mean1' (`sd1')"
putexcel C3 = `r(N)'

*access to private tuition  - Study sample
cd ..
pwd
use "Data\IVR_Data.dta", clear

cd "output"
putexcel set "Table B3.xlsx", modify 

sum child_pvt_tuition
local mean2 = string(r(mean),"%9.2f") 
local sd2 =  string(r(sd),"%9.2f") 
putexcel D3 = "`mean2' (`sd2')"
putexcel E3 = `r(N)'

*school type - BIHS
cd ..
pwd
use "Data\BIHS 18-19\HH_list.dta", replace 

cd "output"
putexcel set "Table B3.xlsx", modify 

replace b2_08a = 0 if b2_08a == 2
sum b2_08a if hh_primay_grade_mem == 1
local mean1 = string(r(mean),"%9.2f") 
local sd1 =  string(r(sd),"%9.2f") 
putexcel B4 = "`mean1' (`sd1')"
putexcel C4 = `r(N)'

*school type - Study sample
cd ..
pwd
use "Data\IVR_Data.dta", clear

cd "output"
putexcel set "Table B3.xlsx", modify 

replace child_school = 0 if child_school != 1
sum child_school
local mean2 = string(r(mean),"%9.2f") 
local sd2 =  string(r(sd),"%9.2f") 
putexcel D4 = "`mean2' (`sd2')"
putexcel E4 = `r(N)'

*Father's age  - BIHS
cd ..
pwd
use "Data\BIHS 18-19\HH_list.dta", replace 

cd "output"
putexcel set "Table B3.xlsx", modify 

sum b1_02 if b1_01==1 & b1_03 == 1  | b1_01==1 & b1_03 == 2 
local mean1 = string(r(mean),"%9.2f") 
local sd1 =  string(r(sd),"%9.2f") 
putexcel B5 = "`mean1' (`sd1')"
putexcel C5 = `r(N)'

*Father's age - Study sample
cd ..
pwd
use "Data\IVR_Data.dta", clear

cd "output"
putexcel set "Table B3.xlsx", modify 

sum father_age
local mean2 = string(r(mean),"%9.2f") 
local sd2 =  string(r(sd),"%9.2f") 
putexcel D5 = "`mean2' (`sd2')"
putexcel E5 = `r(N)'

*Father's Education  - BIHS
cd ..
pwd
use "Data\BIHS 18-19\HH_list.dta", replace 

cd "output"
putexcel set "Table B3.xlsx", modify 

*Education recode 
gen eduN = b1_08
replace eduN = 0 if b1_08 == 99 | b1_08 == 76 
replace eduN = 2 if b1_08 == 66 | b1_08 == 67
replace eduN = 9 if b1_08 == 22
replace eduN = 11 if b1_08 == 33
replace eduN = 16 if b1_08 == 71 | b1_08 == 73
replace eduN = 14 if b1_08 == 72 | b1_08 == 74 | b1_08 == 75
replace eduN = eduN + 1 

*Father's education
sum eduN if b1_01==1 & b1_03 == 1  | b1_01==1 & b1_03 == 2 
local mean1 = string(r(mean),"%9.2f") 
local sd1 =  string(r(sd),"%9.2f") 
putexcel B6 = "`mean1' (`sd1')"
putexcel C6 = `r(N)'

*Father's education - Study sample
cd ..
pwd
use "Data\IVR_Data.dta", clear

cd "output"
putexcel set "Table B3.xlsx", modify 

sum father_edu_years
local mean2 = string(r(mean),"%9.2f") 
local sd2 =  string(r(sd),"%9.2f") 
putexcel D6 = "`mean2' (`sd2')"
putexcel E6 = `r(N)'

*Mother's age - BIHS
cd ..
pwd
use "Data\BIHS 18-19\HH_list.dta", replace 

cd "output"
putexcel set "Table B3.xlsx", modify 

sum b1_02 if b1_01==2 & b1_03 == 1  | b1_01==2 & b1_03 == 2 
local mean1 = string(r(mean),"%9.2f") 
local sd1 =  string(r(sd),"%9.2f") 
putexcel B7 = "`mean1' (`sd1')"
putexcel C7 = `r(N)'

*Mother's age - Study sample
cd ..
pwd
use "Data\IVR_Data.dta", clear

cd "output"
putexcel set "Table B3.xlsx", modify 

sum mother_age
local mean2 = string(r(mean),"%9.2f") 
local sd2 =  string(r(sd),"%9.2f") 
putexcel D7 = "`mean2' (`sd2')"
putexcel E7 = `r(N)'

*Mother's education - BIHS
cd ..
pwd
use "Data\BIHS 18-19\HH_list.dta", replace 

cd "output"
putexcel set "Table B3.xlsx", modify 

*Education recode 
gen eduN = b1_08
replace eduN = 0 if b1_08 == 99 | b1_08 == 76 
replace eduN = 2 if b1_08 == 66 | b1_08 == 67
replace eduN = 9 if b1_08 == 22
replace eduN = 11 if b1_08 == 33
replace eduN = 16 if b1_08 == 71 | b1_08 == 73
replace eduN = 14 if b1_08 == 72 | b1_08 == 74 | b1_08 == 75
replace eduN = eduN + 1 

*Mother's education
sum eduN if b1_01==2 & b1_03 == 1  | b1_01==2 & b1_03 == 2 
local mean1 = string(r(mean),"%9.2f") 
local sd1 =  string(r(sd),"%9.2f") 
putexcel B8 = "`mean1' (`sd1')"
putexcel C8 = `r(N)'

*Mother's education - Study sample
cd ..
pwd
use "Data\IVR_Data.dta", clear

cd "output"
putexcel set "Table B3.xlsx", modify 

sum mother_edu_years
local mean2 = string(r(mean),"%9.2f") 
local sd2 =  string(r(sd),"%9.2f") 
putexcel D8 = "`mean2' (`sd2')"
putexcel E8 = `r(N)'

*Number of households - BIHS
cd ..
pwd
use "Data\BIHS 18-19\HH_list.dta", replace 

drop _merge
merge m:1 a01 using "Data\BIHS 18-19\009_bihs_r3_male_mod_a.dta"
drop if _merge == 2

cd "output"
putexcel set "Table B3.xlsx", modify 
duplicates drop a01, force
sum a23
local mean1 = string(r(mean),"%9.2f") 
local sd1 =  string(r(sd),"%9.2f") 
putexcel B9 = "`mean1' (`sd1')"
putexcel C9 = `r(N)'

*Number of Households - Study sample
cd ..
pwd
use "Data\IVR_Data.dta", clear

cd "output"
putexcel set "Table B3.xlsx", modify 

sum hh_mem
local mean2 = string(r(mean),"%9.2f") 
local sd2 =  string(r(sd),"%9.2f") 
putexcel D9 = "`mean2' (`sd2')"
putexcel E9 = `r(N)'

*Monthly income - BIHS
cd ..
pwd
use "Data\BIHS 18-19\HH_list.dta", replace 

drop _merge
merge m:m a01 mid using "Data\BIHS 18-19\012_bihs_r3_male_mod_c_m.dta"
drop if _merge == 2
bys a01: gen family_income = sum(c14)
bys a01: egen total_family_income = max(family_income)
duplicates drop a01, force

cd "output"
putexcel set "Table B3.xlsx", modify 

sum total_family_income
local mean1 = string(r(mean),"%9.2f") 
local sd1 =  string(r(sd),"%9.2f") 
putexcel B10 = "`mean1' (`sd1')"
putexcel C10 = `r(N)'

*Monthly income - Study sample
cd ..
pwd
use "Data\IVR_Data.dta", clear

cd "output"
putexcel set "Table B3.xlsx", modify 

sum family_income
local mean2 = string(r(mean),"%9.2f") 
local sd2 =  string(r(sd),"%9.2f") 
putexcel D10 = "`mean2' (`sd2')"
putexcel E10 = `r(N)'

*Access to television - BIHS
cd ..
pwd
use "Data\BIHS 18-19\HH_list.dta", replace 

drop _merge
duplicates drop a01, force
merge 1:1 a01 using "Data\BIHS 18-19\015_bihs_r3_male_mod_d1_television.dta"
gen tv_access = _merge == 3
drop if _merge == 2

cd "output"
putexcel set "Table B3.xlsx", modify 

sum tv_access
local mean1 = string(r(mean),"%9.2f") 
local sd1 =  string(r(sd),"%9.2f") 
putexcel B11 = "`mean1' (`sd1')"
putexcel C11 = `r(N)'

*Access to television - Study sample
cd ..
pwd
use "Data\IVR_Data.dta", clear

cd "output"
putexcel set "Table B3.xlsx", modify 

sum television
local mean2 = string(r(mean),"%9.2f") 
local sd2 =  string(r(sd),"%9.2f") 
putexcel D11 = "`mean2' (`sd2')"
putexcel E11 = `r(N)'

*Access to mobile - BIHS
cd ..
pwd
use "Data\BIHS 18-19\HH_list.dta", replace 

drop _merge
duplicates drop a01, force
merge 1:1 a01 using "Data\BIHS 18-19\015_bihs_r3_male_mod_d1_mobile.dta"
gen mobile_access = _merge == 3
drop if _merge == 2

cd "output"
putexcel set "Table B3.xlsx", modify 

sum mobile_access
local mean1 = string(r(mean),"%9.2f") 
local sd1 =  string(r(sd),"%9.2f") 
putexcel B12 = "`mean1' (`sd1')"
putexcel C12 = `r(N)'

*Access to mobile - Study sample
cd ..
pwd
use "Data\IVR_Data.dta", clear

cd "output"
putexcel set "Table B3.xlsx", modify 

sum mobile_access
local mean2 = string(r(mean),"%9.2f") 
local sd2 =  string(r(sd),"%9.2f") 
putexcel D12 = "`mean2' (`sd2')"
putexcel E12 = `r(N)'

*Homestead - BIHS
cd ..
pwd
use "Data\BIHS 18-19\HH_list.dta", replace 

drop _merge
duplicates drop a01, force
merge 1:1 a01 using "Data\BIHS 18-19\020_bihs_r3_male_mod_g_homestead.dta"
drop if _merge == 2
gen homestead = g02

cd "output"
putexcel set "Table B3.xlsx", modify 

sum homestead
local mean1 = string(r(mean),"%9.2f") 
local sd1 =  string(r(sd),"%9.2f") 
putexcel B13 = "`mean1' (`sd1')"
putexcel C13 = `r(N)'

*Homestead - Study sample
cd ..
pwd
use "Data\IVR_Data.dta", clear

cd "output"
putexcel set "Table B3.xlsx", modify 

drop if hs_land >200
sum hs_land
local mean2 = string(r(mean),"%9.2f") 
local sd2 =  string(r(sd),"%9.2f") 
putexcel D13 = "`mean2' (`sd2')"
putexcel E13 = `r(N)'

*Religion - BIHS
cd ..
pwd
use "Data\BIHS 18-19\HH_list.dta", replace 

drop _merge
duplicates drop a01, force
merge 1:1 a01 using "Data\BIHS 18-19\009_bihs_r3_male_mod_a.dta"
drop if _merge == 2

cd "output"
putexcel set "Table B3.xlsx", modify 

replace a13 = 0 if a13 != 1
sum a13
local mean1 = string(r(mean),"%9.2f") 
local sd1 =  string(r(sd),"%9.2f") 
putexcel B14 = "`mean1' (`sd1')"
putexcel C14 = `r(N)'

*Religion - Study sample
cd ..
pwd
use "Data\IVR_Data.dta", clear

cd "output"
putexcel set "Table B3.xlsx", modify 

sum reli_dummy
local mean2 = string(r(mean),"%9.2f") 
local sd2 =  string(r(sd),"%9.2f") 
putexcel D14 = "`mean2' (`sd2')"
putexcel E14 = `r(N)'

*Household Head Occupation - BIHS
cd ..
pwd
use "Data\BIHS 18-19\HH_list.dta", replace 

drop _merge
drop if b1_03 != 1

cd "output"

gen hhh_agri = 1 if b1_10 == 1 | b1_10 == 64 | b1_10 == 65 | b1_10 == 67 | b1_10 == 68 | b1_10 == 69 | b1_10 == 70
replace hhh_agri = 0 if hhh_agri == . 
replace hhh_agri = . if b1_10 == 82 

putexcel set "Table B3.xlsx", modify 

sum hhh_agri
local mean1 = string(r(mean),"%9.2f") 
local sd1 =  string(r(sd),"%9.2f") 
putexcel B15 = "`mean1' (`sd1')"
putexcel C15 = `r(N)'

*Household Head Occupation  - Study sample
cd ..
pwd
use "Data\IVR_Data.dta", clear

cd "output"
putexcel set "Table B3.xlsx", modify 

gen hhh_agri = 1 if father_profession == 2 | father_profession == 8 | father_profession == 5
replace hhh_agri = 0 if hhh_agri == . 
replace hhh_agri = . if father_profession == .
replace hhh_agri = . if father_profession == 1

sum hhh_agri
local mean2 = string(r(mean),"%9.2f") 
local sd2 =  string(r(sd),"%9.2f") 
putexcel D15 = "`mean2' (`sd2')"
putexcel E15 = `r(N)'

***************************************************************************************
*TABLE B4. Percentage of children who answered correctly, by question and treatment
***************************************************************************************
cd ..
pwd
use "Data\IVR_Data.dta", clear
cd "Output"

putexcel set "Table B4.xlsx", replace
putexcel A1 = "Module" A2 = "Bangla literacy" A6= "English literacy" A12 = "Numeracy" A17 = "All"
putexcel (A2:A5) (A6:A11) (A12:A16), merge hcenter vcenter 
putexcel B1 = "Question no" C1 = "Type" D1 = "Marks assigned" E1 = "Standard" F1 = "Extended" G1 = "Control" H1 = "Total sample"
putexcel C2 = "Letter identification/ Reading" D2 = "5" C3 = "Vocabulary" D3 = "5" C4 = "Vocabulary/ Spelling" D4 = "5"  C5 = "Vocabulary/ Spelling" D5 = "5"  C6 = "Letter identification/ Reading" D6 = "6" C7 = "Answering verbally to an English question" D7 = "6"  C8 = "Vocabulary" D8 = "4"  C9 = "Vocabulary" D9 = "4"  C10 = "Vocabulary" D10 = "4"  C11 = "Writing/ Spelling" D11 = "6"  C12 = "Basic numbers" D12 = "6"  C13 = "Addition/ Sorting" D13 = "6"  C14 = "Addition/ Subtraction" D14 = "6"  C15 = "Number conversion" D15 = "6"  C16 = "Addition/ Multiplication" D16 = "6" C17 = "Number of questions answered correctly" D17 = "-"

putexcel set "Table B4.xlsx", modify

local j = 2

forvalues i = 1/15 {
putexcel B`j' 	= `i'
regress e1_item`i' standard_treat extended_treat control_group if endline_completed == 1, nocons cluster(VILLAGE_ID) r
local mean 		= string(_b[standard_treat],"%9.2f")
local se 		= string(_se[standard_treat],"%9.2f")
putexcel E`j' 	= "`mean' (`se')"

local mean 		= string(_b[extended_treat],"%9.2f")
local se 		= string(_se[extended_treat],"%9.2f")
putexcel F`j' 	= "`mean' (`se')"

local mean 		= string(_b[control_group],"%9.2f")
local se 		= string(_se[control_group],"%9.2f")
putexcel G`j' 	= "`mean' (`se')"

sum e1_item`i'
local mean 		= string(`r(mean)',"%9.2f")
local se 		= string((`r(sd)'/sqrt(`r(N)')),"%9.2f")
putexcel H`j' 	= "`mean' (`se')"
 
local j = `j'+1
}

regress endline_total_correct standard_treat extended_treat control_group if endline_completed == 1, nocons cluster(VILLAGE_ID) r
local mean 		= string(_b[standard_treat],"%9.2f")
local se 		= string(_se[standard_treat],"%9.2f")
putexcel E`j' 	= "`mean' (`se')"

local mean 		= string(_b[extended_treat],"%9.2f")
local se 		= string(_se[extended_treat],"%9.2f")
putexcel F`j' 	= "`mean' (`se')"

local mean 		= string(_b[control_group],"%9.2f")
local se 		= string(_se[control_group],"%9.2f")
putexcel G`j' 	= "`mean' (`se')"

sum endline_total_correct
local mean 		= string(`r(mean)',"%9.2f")
local se 		= string((`r(sd)'/sqrt(`r(N)')),"%9.2f")
putexcel H`j' 	= "`mean' (`se')"

***************************************************************************************
*TABLE B5. Treatment effects on number of correct answers
***************************************************************************************
cd ..
pwd
use "Data\IVR_Data.dta", clear
cd "Output"

global control_list 	child_age child_gen baseline_literacy_score baseline_numeracy_score child_pvt_tuition father_edu_years mother_edu_years hh_mem family_income television smartphone hs_land reli_dummy

putexcel set "Table B5.xlsx", replace
putexcel 		A1 = "Outcomes"	B1 = "(1) Control means" ///
				C1 = "(2) Treatment effects - Standard" ///
				D1 = "(3) Treatment effects - Extended"
putexcel		A2 = "Panel A: Number of correct answers"
putexcel 		A3 = "Bangla Literacy [4 Questions]" ///
				A4 = "English Literacy [6 Questions]" ///
				A5 = "Literacy [10 Questions]" ///
				A6 = "Numeracy [5 Questions]" /// 
				A7 = "Total [15 Questions]"
putexcel		A8 = "Panel B: Answered correctly to all questions (0/1)"
putexcel 		A9 = "Bangla Literacy [4 Questions]" ///
				A10 = "English Literacy [6 Questions]" ///
				A11 = "Literacy [10 Questions]" ///
				A12 = "Numeracy [5 Questions]" /// 
				A13 = "Total [15 Questions]"		

gen e1_item_bng = e1_item1 + e1_item2 + e1_item3 + e1_item4 
gen e1_item_eng = e1_item5 + e1_item6 + e1_item7 + e1_item8 + e1_item9 + e1_item10
gen e1_item_lit = e1_item_bng + e1_item_eng
gen e1_item_num = e1_item11 + e1_item12 + e1_item13 + e1_item14 + e1_item15
				
local outcome_vars e1_item_bng e1_item_eng e1_item_lit e1_item_num endline_total_correct

local j = 3

foreach v of local outcome_vars {

regress `v' standard_treat extended_treat control_group if endline_completed == 1, nocons cluster(VILLAGE_ID) r
putexcel set "Table B5.xlsx", modify
local mean 		= string(_b[control_group],"%9.2f")
local se		= string(_se[control_group],"%9.2f")
putexcel B`j' 	= "`mean'(`se')"

regress `v' standard_treat extended_treat i.child_grade_std $control_list if endline_completed == 1, cluster(VILLAGE_ID) r

local mean 		= string(_b[standard_treat],"%9.2f")
local se		= string(_se[standard_treat],"%9.2f")
matrix emat 	= r(table)
local pval		= string(emat[4,1],"%9.4f")
local sig 		= cond(`pval' < 0.005, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.0500, "*", "")))
putexcel C`j' 	= "`mean'`sig'(`se')"

local mean 		= string(_b[extended_treat],"%9.2f")
local se		= string(_se[extended_treat],"%9.2f")
matrix emat 	= r(table)
local pval		= string(emat[4,2],"%9.4f")
local sig 		= cond(`pval' < 0.005, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.0500, "*", "")))
putexcel D`j' 	= "`mean'`sig'(`se')"

local j = `j' + 1
}

gen e1_item_bng_all = e1_item_bng == 4
gen e1_item_eng_all = e1_item_eng == 6
gen e1_item_lit_all = e1_item_lit == 10
gen e1_item_num_all = e1_item_num == 5
gen endline_total_correct_all = endline_total_correct == 15	

local outcome_vars e1_item_bng_all e1_item_eng_all e1_item_lit_all e1_item_num_all endline_total_correct_all

local j = 9

foreach v of local outcome_vars {

regress `v' standard_treat extended_treat control_group if endline_completed == 1, nocons cluster(VILLAGE_ID) r
putexcel set "Table B5.xlsx", modify
local mean 		= string(_b[control_group],"%9.2f")
local se		= string(_se[control_group],"%9.2f")
putexcel B`j' 	= "`mean'(`se')"

regress `v' standard_treat extended_treat i.child_grade_std $control_list if endline_completed == 1, cluster(VILLAGE_ID) r

local mean 		= string(_b[standard_treat],"%9.2f")
local se		= string(_se[standard_treat],"%9.2f")
matrix emat 	= r(table)
local pval		= string(emat[4,1],"%9.4f")
local sig 		= cond(`pval' < 0.005, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.0500, "*", "")))
putexcel C`j' 	= "`mean'`sig'(`se')"

local mean 		= string(_b[extended_treat],"%9.2f")
local se		= string(_se[extended_treat],"%9.2f")
matrix emat 	= r(table)
local pval		= string(emat[4,2],"%9.4f")
local sig 		= cond(`pval' < 0.005, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.0500, "*", "")))
putexcel D`j' 	= "`mean'`sig'(`se')"

local j = `j' + 1
}

putexcel (B2:D13), vcenter hcenter 

***************************************************************************************
*TABLE B6. Heterogenous treatment effects on learning outcome, by quartiles
***************************************************************************************
cd ..
pwd
use "Data\IVR_Data.dta", clear
cd "Output"

drop if endline_completed == 0

egen baseline_result = rowtotal(baseline_literacy_score baseline_numeracy_score)
xtile baseline_result_quartile = baseline_result, n(4)

xtile family_income_quartile = family_income, n(4)

egen parentsedu = rowtotal(father_edu_years mother_edu_years)
xtile parentsedu_quartile = parentsedu, n(4)

putexcel set "Table B6.xlsx", replace
putexcel 	A1 = "Variables"	B1 = "Standard treatment" E1 = "Extended Treatment" 
putexcel 	B2 = "(1) Baseline score" C2 = "(2) Household income" D2 = "(3) Parental education" ///
			E2 = "(4) Baseline score" F2 = "(5) Household income" G2 = "(6) Parental education"
			
putexcel (A1:A2) (B1:D1) (E1:G1), merge vcenter hcenter
			
putexcel 	A3 = "Treatment dummy" A4 = "2nd Quartile" A5 = "3rd Quartile" A6 = "4th Quartile" ///
			A7 = "Treat*2nd Quartile" A8 = "Treat*3rd Quartile" A9 = "Treat*3rd Quartile" ///
			A9 = "Treat*4th Quartile" 

*****************************
*Standard Treatment
*****************************		
foreach var in baseline_result_quartile family_income_quartile parentsedu_quartile {

local i = cond(`var' == baseline_result_quartile, "B", cond(`var' == family_income_quartile, "C", "D"))

regress endline_total_score i.standard_treat i.`var' standard_treat##`var' if endline_completed == 1 & extended_treat == 0, r cluster(VILLAGE_ID)

putexcel set "Table B6.xlsx", modify
local mean 		= string(_b[1.standard_treat],"%9.2f")
local se 		= string(_se[1.standard_treat],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,2], "%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel `i'3 	= "`mean'`sig' (`se')"

local mean 		= string(_b[2.`var'],"%9.2f")
local se 		= string(_se[2.`var'],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,4], "%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel `i'4 	= "`mean'`sig' (`se')"

local mean 		= string(_b[3.`var'],"%9.2f")
local se 		= string(_se[3.`var'],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,5], "%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel `i'5 	= "`mean'`sig' (`se')"

local mean 		= string(_b[4.`var'],"%9.2f")
local se 		= string(_se[4.`var'],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,6], "%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel `i'6 	= "`mean'`sig' (`se')"

local mean 		= string(_b[1.standard_treat#2.`var'],"%9.2f")
local se 		= string(_se[1.standard_treat#2.`var'],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,12], "%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel `i'7 	= "`mean'`sig' (`se')"

local mean 		= string(_b[1.standard_treat#3.`var'],"%9.2f")
local se 		= string(_se[1.standard_treat#3.`var'],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,13], "%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel `i'8 	= "`mean'`sig' (`se')"

local mean 		= string(_b[1.standard_treat#4.`var'],"%9.2f")
local se 		= string(_se[1.standard_treat#4.`var'],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,14], "%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel `i'9 	= "`mean'`sig' (`se')"
}

*****************************
*Extended Treatment
*****************************
foreach var in baseline_result_quartile family_income_quartile parentsedu_quartile {

local i = cond(`var' == baseline_result_quartile, "E", cond(`var' == family_income_quartile, "F", "G"))

regress endline_total_score i.extended_treat i.`var' extended_treat##`var' if endline_completed == 1 & standard_treat == 0, r cluster(VILLAGE_ID)

putexcel set "Table B6.xlsx", modify
local mean 		= string(_b[1.extended_treat],"%9.2f")
local se 		= string(_se[1.extended_treat],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,2], "%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel `i'3 	= "`mean'`sig' (`se')"

local mean 		= string(_b[2.`var'],"%9.2f")
local se 		= string(_se[2.`var'],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,4], "%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel `i'4 	= "`mean'`sig' (`se')"

local mean 		= string(_b[3.`var'],"%9.2f")
local se 		= string(_se[3.`var'],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,5], "%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel `i'5 	= "`mean'`sig' (`se')"

local mean 		= string(_b[4.`var'],"%9.2f")
local se 		= string(_se[4.`var'],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,6], "%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel `i'6 	= "`mean'`sig' (`se')"

local mean 		= string(_b[1.extended_treat#2.`var'],"%9.2f")
local se 		= string(_se[1.extended_treat#2.`var'],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,12], "%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel `i'7 	= "`mean'`sig' (`se')"

local mean 		= string(_b[1.extended_treat#3.`var'],"%9.2f")
local se 		= string(_se[1.extended_treat#3.`var'],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,13], "%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel `i'8 	= "`mean'`sig' (`se')"

local mean 		= string(_b[1.extended_treat#4.`var'],"%9.2f")
local se 		= string(_se[1.extended_treat#4.`var'],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,14], "%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel `i'9 	= "`mean'`sig' (`se')"
}	

***************************************************************************************
*TABLE B7. Parents' social desirability bias analysis
***************************************************************************************
cd ..
pwd
use "Data\IVR_Data.dta", clear
cd "Output"

global control_list 	child_age child_gen baseline_literacy_score baseline_numeracy_score child_pvt_tuition father_edu_years mother_edu_years hh_mem family_income television smartphone hs_land reli_dummy

todummy social_desire_mother, median 

putexcel set "Table B7.xlsx", replace 
putexcel 	A1 = "Variables"	B1 = "T1: Standard"	E1 = "T2: Extended"
putexcel 	(A1:A2) (B1:D1) (E1:G1), merge hcenter vcenter
putexcel 	B2 = "(1) Above median"		C2 = "(2) Below median" 	D2 = "(3) Interaction" ///
			E2 = "(4) Above median"		F2 = "(5) Below median" 	G2 = "(6) Interaction"

putexcel 	A3 	= "Leadership" 				A4 = "Communication" 	A5	= "Planning" ///
			A6	= "Emotional symptoms" 		A7 = "Conduct problem" 	A8 = "Hyperactivity" ///
			A9	= "Peer problem" A10 = "Prosocial" ///
			A11 = "Student's study time" 	A12 = "Caregiver's time in homeschooling" 

local std_mother_vars 	leadership_std communication_std planning_std sdq_emotion_std sdq_conduct_std sdq_hyper_std sdq_peer_std sdq_prosocial_std study_time_child_std  homeschooling_time_std 

local j = 3 

foreach v of local std_mother_vars {
regress `v' i.standard_treat i.d_social_desire_mother standard_treat##d_social_desire_mother $control_list i.child_grade_std ///
if endline_completed == 1 & extended_treat == 0 & d_social_desire_mother == 1, r cluster(VILLAGE_ID)

putexcel set "Table B7.xlsx", modify 

local mean 		= string(_b[1.standard_treat],"%9.2f")
local se 		= string(_se[1.standard_treat],"%9.2f")
matrix emat 	= r(table)
local pval 		= string(emat[4,2],"%9.4f")
local sig		= cond(`pval' < 0.005, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.0500, "*", "")))
putexcel B`j' 	= "`mean'`sig' (`se')"

regress `v' i.standard_treat i.d_social_desire_mother standard_treat##d_social_desire_mother $control_list i.child_grade_std ///
if endline_completed == 1 & extended_treat == 0 & d_social_desire_mother == 0, r cluster(VILLAGE_ID)

local mean 		= string(_b[1.standard_treat],"%9.2f")
local se 		= string(_se[1.standard_treat],"%9.2f")
matrix emat 	= r(table)
local pval 		= string(emat[4,2],"%9.4f")
local sig		= cond(`pval' < 0.005, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.0500, "*", "")))
putexcel C`j' 	= "`mean'`sig' (`se')"

regress `v' i.standard_treat i.d_social_desire_mother standard_treat##d_social_desire_mother $control_list i.child_grade_std ///
if endline_completed == 1 & extended_treat == 0, r cluster(VILLAGE_ID)

local mean 		= string(_b[1.standard_treat#1.d_social_desire_mother],"%9.2f")
local se 		= string(_se[1.standard_treat#1.d_social_desire_mother],"%9.2f")
matrix emat 	= r(table)
local pval 		= string(emat[4,8],"%9.4f")
local sig		= cond(`pval' < 0.005, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.0500, "*", "")))
putexcel D`j' 	= "`mean'`sig' (`se')"

regress `v' i.extended_treat i.d_social_desire_mother extended_treat##d_social_desire_mother $control_list i.child_grade_std ///
if endline_completed == 1 & standard_treat == 0 & d_social_desire_mother == 1, r cluster(VILLAGE_ID)

local mean 		= string(_b[1.extended_treat],"%9.2f")
local se 		= string(_se[1.extended_treat],"%9.2f")
matrix emat 	= r(table)
local pval 		= string(emat[4,2],"%9.4f")
local sig		= cond(`pval' < 0.005, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.0500, "*", "")))
putexcel E`j' 	= "`mean'`sig' (`se')"

regress `v' i.extended_treat i.d_social_desire_mother extended_treat##d_social_desire_mother $control_list i.child_grade_std ///
if endline_completed == 1 & standard_treat == 0 & d_social_desire_mother == 0, r cluster(VILLAGE_ID)

local mean 		= string(_b[1.extended_treat],"%9.2f")
local se 		= string(_se[1.extended_treat],"%9.2f")
matrix emat 	= r(table)
local pval 		= string(emat[4,2],"%9.4f")
local sig		= cond(`pval' < 0.005, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.0500, "*", "")))
putexcel F`j' 	= "`mean'`sig' (`se')"

regress `v' i.extended_treat i.d_social_desire_mother extended_treat##d_social_desire_mother $control_list i.child_grade_std ///
if endline_completed == 1 & standard_treat == 0, r cluster(VILLAGE_ID)

local mean 		= string(_b[1.extended_treat#1.d_social_desire_mother],"%9.2f")
local se 		= string(_se[1.extended_treat#1.d_social_desire_mother],"%9.2f")
matrix emat 	= r(table)
local pval 		= string(emat[4,8],"%9.4f")
local sig		= cond(`pval' < 0.005, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.0500, "*", "")))
putexcel G`j' 	= "`mean'`sig' (`se')"

local j = `j' + 1
}

putexcel (B2:G12), vcenter hcenter 

***************************************************************************************
*TABLE B8. Child's social desirability bias analysis
***************************************************************************************
cd ..
pwd
use "Data\IVR_Data.dta", clear
cd "Output"

global control_list 	child_age child_gen baseline_literacy_score baseline_numeracy_score child_pvt_tuition father_edu_years mother_edu_years hh_mem family_income television smartphone hs_land reli_dummy

todummy social_desire_child, median 

putexcel set "Table B8.xlsx", replace 
putexcel 	A1 = "Variables"	B1 = "T1: Standard"	E1 = "T2: Extended"
putexcel 	(A1:A2) (B1:D1) (E1:G1), merge hcenter vcenter
putexcel 	B2 = "(1) Above median"		C2 = "(2) Below Median" 	D2 = "(3) Interaction" ///
			E2 = "(4) Above median"		F2 = "(5) Below Median" 	G2 = "(6) Interaction"

putexcel 	A3 	= "Overall impulsivity" A4 = "Schoolwork impulsivity" 	A5	= "Interpersonal impulsivity" A6	= "Girt" A7 = "Growth mindset" A8 = "Affective empathy (Contagion)" A9	= "Cognitive empathy (Understanding)" A10 = "Prosocial motivation (Support)"

local std_child_vars 	impulsivity_overall_std impulsivity_schoolwork_std impulsivity_interpersonal_std grit_std gms_std affective_empathy_std cognitive_empathy_std prosocial_empathy_std

local j = 3 

foreach v of local std_child_vars {
regress `v' i.standard_treat i.d_social_desire_child standard_treat##d_social_desire_child $control_list i.child_grade_std /// 
if endline_completed == 1 & extended_treat == 0 & d_social_desire_child == 1, r cluster(VILLAGE_ID)

putexcel set "Table B8.xlsx", modify 

local mean 		= string(_b[1.standard_treat],"%9.2f")
local se 		= string(_se[1.standard_treat],"%9.2f")
matrix emat 	= r(table)
local pval 		= string(emat[4,2],"%9.4f")
local sig		= cond(`pval' < 0.005, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.0500, "*", "")))
putexcel B`j' 	= "`mean'`sig' (`se')"

regress `v' i.standard_treat i.d_social_desire_child standard_treat##d_social_desire_child $control_list i.child_grade_std /// 
if endline_completed == 1 & extended_treat == 0 & d_social_desire_child == 0, r cluster(VILLAGE_ID)

local mean 		= string(_b[1.standard_treat],"%9.2f")
local se 		= string(_se[1.standard_treat],"%9.2f")
matrix emat 	= r(table)
local pval 		= string(emat[4,2],"%9.4f")
local sig		= cond(`pval' < 0.005, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.0500, "*", "")))
putexcel C`j' 	= "`mean'`sig' (`se')"

regress `v' i.standard_treat i.d_social_desire_child standard_treat##d_social_desire_child $control_list i.child_grade_std ///
if endline_completed == 1 & extended_treat == 0, r cluster(VILLAGE_ID)

local mean 		= string(_b[1.standard_treat#1.d_social_desire_child],"%9.2f")
local se 		= string(_se[1.standard_treat#1.d_social_desire_child],"%9.2f")
matrix emat 	= r(table)
local pval 		= string(emat[4,8],"%9.4f")
local sig		= cond(`pval' < 0.005, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.0500, "*", "")))
putexcel D`j' 	= "`mean'`sig' (`se')"

regress `v' i.extended_treat i.d_social_desire_child extended_treat##d_social_desire_child  $control_list i.child_grade_std ///
if endline_completed == 1 & standard_treat == 0 & d_social_desire_child == 1, r cluster(VILLAGE_ID)

local mean 		= string(_b[1.extended_treat],"%9.2f")
local se 		= string(_se[1.extended_treat],"%9.2f")
matrix emat 	= r(table)
local pval 		= string(emat[4,2],"%9.4f")
local sig		= cond(`pval' < 0.005, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.0500, "*", "")))
putexcel E`j' 	= "`mean'`sig' (`se')"

regress `v' i.extended_treat i.d_social_desire_child extended_treat##d_social_desire_child  $control_list i.child_grade_std ///
if endline_completed == 1 & standard_treat == 0 & d_social_desire_child == 0, r cluster(VILLAGE_ID)

local mean 		= string(_b[1.extended_treat],"%9.2f")
local se 		= string(_se[1.extended_treat],"%9.2f")
matrix emat 	= r(table)
local pval 		= string(emat[4,2],"%9.4f")
local sig		= cond(`pval' < 0.005, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.0500, "*", "")))
putexcel F`j' 	= "`mean'`sig' (`se')"

regress `v' i.extended_treat i.d_social_desire_child extended_treat##d_social_desire_child  $control_list i.child_grade_std ///
if endline_completed == 1 & standard_treat == 0, r cluster(VILLAGE_ID)

local mean 		= string(_b[1.extended_treat#1.d_social_desire_child],"%9.2f")
local se 		= string(_se[1.extended_treat#1.d_social_desire_child],"%9.2f")
matrix emat 	= r(table)
local pval 		= string(emat[4,8],"%9.4f")
local sig		= cond(`pval' < 0.005, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.0500, "*", "")))
putexcel G`j' 	= "`mean'`sig' (`se')"

local j = `j' + 1
}

putexcel (B3:G10), vcenter hcenter

***************************************************************************************
*Table B9. Relationships between percent of completed lessons 
*ever repeated and baseline characteristics
***************************************************************************************
cd ..
pwd
use "Data\IVR_Data.dta", clear
cd "Output"

local baseline_x "child_age child_gen child_pvt_tuition hh_mem reli_dummy television smartphone hs_land"

reg reppct_lit low_parent low_base_lit low_family_inc `baseline_x' if any_treat==1 & endline_completed==1 & matchphone==1, cl(VILLAGE)
est store a1

reg reppct_num low_parent low_base_num low_family_inc `baseline_x' if any_treat==1 & endline_completed==1 & matchphone==1, cl(VILLAGE)
est store a2

reg reppct_lit low_parent low_base_lit low_family_inc `baseline_x' matchphone if any_treat==1 & endline_completed==1 & totlessons_lit~=., cl(VILLAGE)
est store a3

reg reppct_num low_parent low_base_num low_family_inc `baseline_x' matchphone if any_treat==1 & endline_completed==1 & totlessons_num~=., cl(VILLAGE)
est store a4

reg reppct_lit low_parent low_base_lit low_family_inc `baseline_x' if any_treat==1 & endline_completed==1, cl(VILLAGE)
est store a5

reg reppct_num low_parent low_base_num low_family_inc `baseline_x' if any_treat==1 & endline_completed==1, cl(VILLAGE)
est store a6

esttab a* using "Table B9.csv", nogap title("TARL") keep(low_parent_edu low_base_* low_family_inc) ///
	b(%8.2f) se(%8.2f) r2 nolabel star(* 0.05 ** 0.01 *** 0.001) replace

***************************************************************************************
*TABLE B10. Reliability of endline assessment test questions
***************************************************************************************
cd ..
pwd
use "Data\IVR_Data.dta", clear
cd "Output"

alpha e1_cog_1 - e1_cog_4 e1_cog_9 - e1_cog_19 if endline_completed == 1, std
putexcel set "Table B10.xlsx", replace
putexcel A1 = "Subject"	B1 = "Alpha" C1 = "Omega" D1 = "Correlation" E1 = "No of questions" F1 = "No of students"
putexcel A2 = "All questions"		B2 = (string((r(alpha)), "%9.2f")) 	D2 = (string((r(rho)), "%9.2f")) 	E2 = (r(k))				F2 = "1690"

alpha e1_cog_1 - e1_cog_4 e1_cog_9 - e1_cog_14 if endline_completed == 1, std
putexcel set "Table B10.xlsx", modify
putexcel A3 = "Literacy"			B3 = (string((r(alpha)), "%9.2f"))	D3 = (string((r(rho)), "%9.2f"))	E3 = (r(k))				F3 = "1690"

alpha e1_cog_15 - e1_cog_19 if endline_completed == 1, std 
putexcel A4 = "Numeracy"			B4 = (string((r(alpha)), "%9.2f"))	D4 = (string((r(rho)), "%9.2f"))	E4 = (r(k))				F4 = "1690"

omegacoef e1_cog_1 - e1_cog_4 e1_cog_9 - e1_cog_19
putexcel C2 = (string((r(omega)), "%9.2f"))

omegacoef e1_cog_1 - e1_cog_4 e1_cog_9 - e1_cog_14
putexcel C3 = (string((r(omega)), "%9.2f"))

omegacoef  e1_cog_15 - e1_cog_19
putexcel C4 = (string((r(omega)), "%9.2f"))
putexcel (B1:F4), vcenter hcenter 

***************************************************************************************
*Table B11. Differential Item Functioning (DIF) analysis
***************************************************************************************
cd ..
pwd
use "Data\IVR_Data.dta", clear
cd "Output"

drop if endline_completed==0

gen dif_e1_item1 	= e1_cog_1 
gen dif_e1_item2 	= e1_cog_2 
gen dif_e1_item3 	= e1_cog_3 
gen dif_e1_item4 	= e1_cog_4 
gen dif_e1_item5 	= e1_cog_9 
gen dif_e1_item6 	= e1_cog_10 
gen dif_e1_item7 	= e1_cog_11 
gen dif_e1_item8 	= e1_cog_12 
gen dif_e1_item9 	= e1_cog_13 
gen dif_e1_item10 	= e1_cog_14 
gen dif_e1_item11 	= e1_cog_15 
gen dif_e1_item12 	= e1_cog_16 
gen dif_e1_item13 	= e1_cog_17 
gen dif_e1_item14 	= e1_cog_18 
gen dif_e1_item15 	= e1_cog_19 

foreach var in dif_e1* {
recode `var' (0=0) (.=.) (1/10=1)
}

irt 2pl dif_e1_i*, group(any_treat)
estimates store constrained_e1

*item 1
irt (0: 2pl dif_e1_item1) (1: 2pl dif_e1_item1) (2pl dif_e1_item2-dif_e1_item15), group(any_treat)
estimates store item1_e1

lrtest constrained_e1 item1_e1
putexcel set "Table B11.xlsx", replace
putexcel A1 = "Question number"		B1 = "Chi-square"				C1 = "P-value"
putexcel A2 = (1)										B2 = ( r(chi2))						C2 = (r(p))

*item 2
irt (0: 2pl dif_e1_item2) (1: 2pl dif_e1_item2) (2pl dif_e1_item1 dif_e1_item3-dif_e1_item15), group(any_treat)
estimates store item2_e1

lrtest constrained_e1 item2_e1
putexcel set "Table B11.xlsx", modify
putexcel A3 = (2)				B3 = ( r(chi2))				C3 = (r(p))

*item 3
irt (0: 2pl dif_e1_item3) (1: 2pl dif_e1_item3) (2pl dif_e1_item1-dif_e1_item2 dif_e1_item4-dif_e1_item15), group(any_treat)
estimates store item3_e1

lrtest constrained_e1 item3_e1
putexcel A4 = (3)				B4 = (r(chi2))				C4 = (r(p))

*item 4
irt (0: 2pl dif_e1_item4) (1: 2pl dif_e1_item4) (2pl dif_e1_item1-dif_e1_item3 dif_e1_item5-dif_e1_item15), group(any_treat)
estimates store item4_e1

lrtest constrained_e1 item4_e1
putexcel A5 = (4)				B5 = ( r(chi2))				C5 = (r(p))

*item 5
irt (0: 2pl dif_e1_item5) (1: 2pl dif_e1_item5) (2pl dif_e1_item1-dif_e1_item4 dif_e1_item6-dif_e1_item15), group(any_treat)
estimates store item5_e1

lrtest constrained_e1 item5_e1
putexcel A6 = (5)				B6 = ( r(chi2))				C6 = (r(p))

*item 6
irt (0: 2pl dif_e1_item6) (1: 2pl dif_e1_item6) (2pl dif_e1_item1-dif_e1_item5 dif_e1_item7-dif_e1_item15), group(any_treat)
estimates store item6_e1

lrtest constrained_e1 item6_e1
putexcel A7 = (6)				B7 = ( r(chi2))				C7 = (r(p))

*item 7
irt (0: 2pl dif_e1_item7) (1: 2pl dif_e1_item7) (2pl dif_e1_item1-dif_e1_item6 dif_e1_item8-dif_e1_item15), group(any_treat)
estimates store item7_e1

lrtest constrained_e1 item7_e1
putexcel A8 = (7)				B8 = ( r(chi2))				C8 = (r(p))

*item 8
irt (0: 2pl dif_e1_item8) (1: 2pl dif_e1_item8) (2pl dif_e1_item1-dif_e1_item7 dif_e1_item9-dif_e1_item15), group(any_treat)
estimates store item8_e1

lrtest constrained_e1 item8_e1
putexcel A9 = (8)				B9 = (r(chi2))				C9 = (r(p))

*item 9
irt (0: 2pl dif_e1_item9) (1: 2pl dif_e1_item9) (2pl dif_e1_item1-dif_e1_item8 dif_e1_item10-dif_e1_item15), group(any_treat)
estimates store item9_e1

lrtest constrained_e1 item9_e1
putexcel A10 = (9)				B10 = ( r(chi2))				C10 = (r(p))

*item 10
irt (0: 2pl dif_e1_item10) (1: 2pl dif_e1_item10) (2pl dif_e1_item1-dif_e1_item9 dif_e1_item11-dif_e1_item15), group(any_treat)
estimates store item10_e1

lrtest constrained_e1 item10_e1
putexcel A11 = (10)	B11 = ( r(chi2))	C11 = (r(p))

*item 11
irt (0: 2pl dif_e1_item11) (1: 2pl dif_e1_item11) (2pl dif_e1_item1-dif_e1_item10 dif_e1_item12-dif_e1_item15), group(any_treat)
estimates store item11_e1

lrtest constrained_e1 item11_e1
putexcel A12 = (11)	B12 = ( r(chi2))	C12 = (r(p))

*item 12
irt (0: 2pl dif_e1_item12) (1: 2pl dif_e1_item12) (2pl dif_e1_item1-dif_e1_item11 dif_e1_item13-dif_e1_item15), group(any_treat)
estimates store item12_e1

lrtest constrained_e1 item12_e1
putexcel A13 = (12)	B13 = ( r(chi2))	C13 = (r(p))

*item 13
irt (0: 2pl dif_e1_item13) (1: 2pl dif_e1_item13) (2pl dif_e1_item1-dif_e1_item12 dif_e1_item14-dif_e1_item15), group(any_treat)
estimates store item13_e1

lrtest constrained_e1 item13_e1
putexcel A14 = (13)	B14 = ( r(chi2))	C14 = (r(p))

*item 14
irt (0: 2pl dif_e1_item14) (1: 2pl dif_e1_item14) (2pl dif_e1_item1-dif_e1_item13 dif_e1_item15), group(any_treat)
estimates store item14_e1 

lrtest constrained_e1 item14_e1
putexcel A15 = (14)	B15 = ( r(chi2))	C15 = (r(p))

*item 15
irt (0: 2pl dif_e1_item15) (1: 2pl dif_e1_item15) (2pl dif_e1_item1-dif_e1_item14), group(any_treat)
estimates store item15_e1

lrtest constrained_e1 item15_e1
putexcel A16 = (15)	B16 = ( r(chi2))	C16 = (r(p))

***************************************************************************************
*TABLE B12. Differential Item Functioning (DIF) adjusted learning outcome
***************************************************************************************
cd ..
pwd
use "Data\IVR_Data.dta", clear
cd "Output"

gen dif_e1_item1 	= e1_cog_1 
gen dif_e1_item2 	= e1_cog_2 
gen dif_e1_item3 	= e1_cog_3 
gen dif_e1_item4 	= e1_cog_4 
gen dif_e1_item5 	= e1_cog_9 
gen dif_e1_item6 	= e1_cog_10 
gen dif_e1_item7 	= e1_cog_11 
gen dif_e1_item8 	= e1_cog_12 
gen dif_e1_item9 	= e1_cog_13 
gen dif_e1_item10 	= e1_cog_14 
gen dif_e1_item11 	= e1_cog_15
gen dif_e1_item12 	= e1_cog_16
gen dif_e1_item13 	= e1_cog_17
gen dif_e1_item14 	= e1_cog_18
gen dif_e1_item15 	= e1_cog_19

global control_list child_age child_gen baseline_literacy_score baseline_numeracy_score child_pvt_tuition father_edu_years mother_edu_years hh_mem family_income television smartphone hs_land reli_dummy

egen 	dif_adj_literacy 	= rowtotal(dif_e1_item1 dif_e1_item2 dif_e1_item3 dif_e1_item4 dif_e1_item5 dif_e1_item6 dif_e1_item7 dif_e1_item9)

egen 	dif_adj_numeracy	= rowtotal(dif_e1_item11 dif_e1_item13 dif_e1_item15)

gen 	dif_adj_total		= dif_adj_literacy + dif_adj_numeracy

local outcome_vars dif_adj_total dif_adj_literacy dif_adj_numeracy

foreach v of local outcome_vars {
sum `v' if treatment_arms == 3
gen `v'_cmean = r(mean)
gen `v'_csd= r(sd)
gen `v'_std= (`v' - `v'_cmean)/`v'_csd
drop `v'_cmean `v'_csd 
} 

putexcel set "Table B12.xlsx", replace 
putexcel A1 = "Variable"												B1 = "T1: Standard"																				D1 = "T2: Extended"
putexcel B2 = "Coefficient on treatment dummy" C2 = "t-test P-value"	D2 = "Coefficient on Treatment dummy"	E2 = "t-test P-value"
putexcel (A1:A2) (B1:C1) (D1:E1), merge hcenter vcenter

putexcel A3 = "Total score" 	A4 = "Literacy" 		A5 = "Numeracy" 

local 	std_outcome_vars 	dif_adj_total_std dif_adj_literacy_std dif_adj_numeracy_std
global 	control_list 		child_age child_gen baseline_literacy_score baseline_numeracy_score child_pvt_tuition father_edu_years mother_edu_years hh_mem family_income television smartphone hs_land reli_dummy

local j = 3

foreach v of local std_outcome_vars {
regress `v' standard_treat extended_treat $control_list i.child_grade_std if endline_completed == 1, r cluster(VILLAGE_ID)

putexcel set "Table B12.xlsx", modify 

local mean 		= string(_b[standard_treat],"%9.2f")
local se 		= string(_se[standard_treat],"%9.2f")
matrix emat		= r(table)
local pval 		= string(emat[4,2],"%9.4f")
local sig		= cond(`pval' < 0.005, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.0500, "*", "")))
putexcel B`j' 	= "`mean'`sig' (`se')"
putexcel C`j'	= "`pval'"

local mean 		= string(_b[extended_treat],"%9.2f")
local se 		= string(_se[extended_treat],"%9.2f")
local pval 		= string(emat[4,2],"%9.4f")
local sig		= cond(`pval' < 0.005, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.0500, "*", "")))
putexcel D`j' 	= "`mean'`sig' (`se')"
putexcel E`j'	= "`pval'"

local j = `j' + 1
}

putexcel (B1:E5), hcenter vcenter

clear 